﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
using EntLib.Domain.Common;

namespace Entity
{
    public abstract class Base : ISetProperty
    {
        /// <summary>
        /// 设置公共属性值
        /// </summary>
        /// <param name="idr">数据接口</param>
        /// <param name="fields">数据选取字段集合，必需跟实体层的字段名称一样，若选取字段为*，即选取全部字段时，实体层的字段必需跟数据表的字段一至</param>
        public void SetProperty(IDataReader idr,IList<string> fields)
        {
            
            PropertyInfo[] propertyInfos = this.GetType().GetProperties();
            foreach (PropertyInfo item in propertyInfos)
            {
                //if (idr[item.Name] != DBNull.Value)
                if (fields.Contains(item.Name) && idr[item.Name] != DBNull.Value)
                {
                    item.SetValue(this, idr[item.Name], null);
                }
            }
        }
    }
}
